package base;

/**
 * @author Lby蓝
 * @version 1.0
 * @since 1.8
 */

public class Operator {

    public static void unaryOperation() {
        //一元运算符 ++ --
        int a = 3;
        int b = a++;
        int c = ++a;
        System.out.println(a+","+b+","+c);
    }

    public static void binaryOperation() {
        //二元运算符 + - * / %
        //关系运算符 > < == >= <= !=
        int a = 10;
        int b = 15;
        int c = 20;
        int d = 25;
        System.out.println(c/b);
        System.out.println(c%b);

        //幂运算 Math.pow
        System.out.println(Math.pow(5,7));
    }

    public static void logicOperation() {
        //逻辑运算符 && || !
        boolean a = true;
        boolean b = false;

        int c = 6;
        boolean d = (c<4)&&(c++>4);

        System.out.println(a&&b);
        System.out.println(a||b);
        System.out.println(!a&&b);
        System.out.println(c);
    }

    public static void bitOperation() {
        //位运算符 & | ^ ~ << >> >>>
        /*
        A = 0011 1100
        B = 0000 1101

        A&B = 0000 1100
        A|B = 0011 1101
        A^B = 0011 0001
        ~A = 1100 0011

        效率位运算 << >>
        1   0000 0001
        2   0000 0010
        3   0000 0011
        4   0000 0100
         */
        int num1 = 2*8;
        System.out.println(2<<3);
        System.out.println(2>>3);
        byte num2 = (byte) (1<<7);
        byte num3 = 2;
        System.out.println(num2);
        System.out.println(num3 <<6);
    }

    public static void expandOperator() {
        //三目运算符 ? :
        int score = 18;
        String type = score<16 ? "未成年" : "成年";
        System.out.println(type);

        //查看隐式输出转换
        System.out.println(1+' '+4+""+12);
        System.out.println(""+1+12);
    }


    public static void main(String[] args) {
        //unaryOperation();
        //binaryOperation();
        //logicOperation();
        //bitOperation();
        expandOperator();
    }
}
